﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DeJC.BLL;
using DeJC.BLL.Managers;
using DeJC.DAL.Model;
using DeJC.DAL.Repository;
using TheList.Helper;

namespace TheList.Controllers
{
    public class CountriesController : Controller
    {
        TheListEntities db = new TheListEntities();
        //
        // GET: /Countries/

        public ActionResult Index()
        {
            CountryRepository cr = new CountryRepository(db);
            //List<Country> countries = ;

            return View(cr.GetAll());
        }

        //
        // GET: /Countries/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Countries/Create

        public ActionResult Create()
        {
            ViewBag.LanguageID = new SelectList(GeneralMiscTypeManager.GetChildren(Utility.ParentLanguageId), "ID", "Name");
            return View();
        } 

        //
        // POST: /Countries/Create

        [HttpPost]
        public ActionResult Create(Country country)
        {

            if(ModelState.IsValid)
            {
                CountryManager.AddCountry(country);
                return RedirectToAction("Index");
                
            }
            ViewBag.LanguageID=new SelectList(GeneralMiscTypeManager.GetChildren(Utility.ParentLanguageId), "ID", "Name",country.LanguageID);
            return View();
        }
        
        //
        // GET: /Countries/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Countries/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Countries/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Countries/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
